new Vue({
    el: '#cele',
    data: {
        time:'',
        flag:'',
        peploeList:[],
        form: {
            Number:'',
            Name:'',
            Birthday:'',
            Nation:'',
            Degree:'',
            Politics_status:'',
            Politics_time:'',
            Military_time:'',
            Police_rank:'',
            Duty:'',
            Profession_posts:'',
            Address:'',
            Contact:'',
            Soldier_id:'',
            Id_number:'',
            Is_leader:'',
            Is_contact:'',
            Is_driver:'',
            Is_normal:'',
            Fire_brigade_num:'',
            Fire_brigade_name:'',
            Status:''
        },
        FireManInfoModel:{},
        UserRoleRelationModel:{}
    },
    mounted() {
        this.restaurants = this.loadAll();
        this.FireManInfoModel = $.parseJSON(localStorage.getItem('msg'));
        console.log(this.FireManInfoModel.Fire_brigade_num)
        this.UserRoleRelationModel = $.parseJSON(localStorage.getItem('item'));

        //var Vue = this
        //var  _FireManInfoModel={},_UserRoleRelationModel={}
        //var c = $.cookie('token')
        //debugger
        //if (c == '' || c == undefined) {
        //    //  token 如果等于空 返回登陆页
        //    window.location.href = '../login.html'
        //} else {
        var _Vue = this
        setInterval(function () {
            var time = new Date();
            var y = time.getFullYear();
            var m = time.getMonth() + 1;
            var d = time.getDate();
            var h = time.getHours();
            var mm = time.getMinutes();
            var s = time.getSeconds();
            _Vue.time = y + '年' + _Vue.add0(m) + '月' + _Vue.add0(d) + '日  ' + _Vue.add0(h) + ':' + _Vue.add0(mm) + ':' + _Vue.add0(s);
        }, 1000)

        $('.main-left-bj ul li a').click(function () {
            //console.log(this)
            $(this).find('span').toggleClass('glyphicon-plus glyphicon-minus yellow-text')
        });
        //  存储信息
       /* _Vue.FireManInfoModel = $.parseJSON(localStorage.getItem('msg'));
        console.log(_Vue.FireManInfoModel)
        _Vue.UserRoleRelationModel = $.parseJSON(localStorage.getItem('item'));
        var a =  _Vue.FireManInfoModel;
        var b = _Vue.UserRoleRelationModel;*/
        this.ajaxProceedFire()
        this.ajaxGetModelBySoldierId()
    },
    computed:{




    },
    methods:{

        //弹窗
        goin(index){
            debugger
            this.flag='1'
            this.ajaxGetModelBySoldierId(index)
        },
        quxiao(){
            this.flag=false
        },
        /*模拟数据*/
        querySearch(queryString, cb) {
            var restaurants = this.restaurants;
            var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        createFilter(queryString) {
            return (restaurant) => {
                debugger
                return (restaurant.value.indexOf(queryString) === 0);
            };
        },
        handleSelect(item) {
            console.log(item);
        },
        loadAll() {
            return [
                {value:"汉族"},
                {value:"蒙古族"},
                {value:"回族"},
                {value:"藏族"},
                {value:"维吾尔族"},
                {value:"苗族"},
                {value:"彝族"},
                {value:"壮族"},
                {value:"布依族"},
                {value:"朝鲜族"},
                {value:"满族"},
                {value:"侗族"},
                {value:"瑶族"},
                {value:"白族"},
                {value:"土家族"},
                {value:"哈尼族"},
                {value:"哈萨克族"},
                {value:"傣族"},
                {value:"黎族"},
                {value:"傈僳族"},
                {value:"佤族"},
                {value:"畲族"},
                {value:"高山族"},
                {value:"拉祜族"},
                {value:"水族"},
                {value:"东乡族"},
                {value:"纳西族"},
                {value:"景颇族"},
                {value:"柯尔克孜族"},{value:"土族"},
                {value:"达斡尔族"},
                {value:"仫佬族"},
                {value:"羌族"},
                {value:"布朗族"},
                {value:"撒拉族"},
                {value:"毛难族"},
                {value:"仡佬族"},
                {value:"锡伯族"},{value:"阿昌族"},
                {value:"普米族"},
                {value:"塔吉克族"},
                {value:"怒族"},
                {value:"乌孜别克族"},
                {value:"俄罗斯族"},
                {value:"鄂温克族"},
                {value:"崩龙族"},
                {value:"保安族"},
                {value:"裕固族"},
                {value:"京族"},
                {value:"塔塔尔族"},
                {value:"独龙族"},
                {value:"鄂伦春族"},
                {value:"赫哲族"},
                {value:"门巴族"},
                {value:"珞巴族"},
                {value:"基诺族"}
            ];
        },
        ajaxProceedFire(index){
            debugger
            var c = []
            if(index==undefined){
                c= this.FireManInfoModel.Fire_brigade_num
            }else {
                c = index
            }
            var Vue = this;
            //console.log(this.FireManInfoModel)
            $.ajax({
                type: 'post',
                url: Url+'FireManApi/GetFireManInfoListActive',
                data: JSON.stringify({ BrigadeNumber:c}),//中队编号
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    debugger
                    //console.log(this.FireManInfoModel)
                    console.log(msg)
                    Vue.peploeList= msg.data
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        },
        ajaxGetModelBySoldierId(index){
            debugger
            var Vue = this;
            //console.log(this.FireManInfoModel)
            $.ajax({
                type: 'post',
                url: Url+'FireManApi/GetModelBySoldierId',
                data: JSON.stringify({SoldierId:index}),
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    if(msg.state==8){
                        Vue.$message({
                            showClose: true,
                            message: '消防员已存在，无法插',
                            type: 'success'
                        });
                        Vue.form = msg.data
                    }
                    if(msg.state==1&&msg.msg!="未查询到消防队员信息"){
                        Vue.form = msg.data
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        },
        InsertFireManInfoModel(){
            debugger
            var Vue = this;
            //console.log(this.FireManInfoModel)
            $.ajax({
                type: 'post',
                url: Url+'FireManApi/InsertFireManInfoModel',
                data: JSON.stringify(Vue.form),
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    if(msg.state == 1){
                        Vue.$message({
                            showClose: true,
                            message: '新增成功',
                            type: 'success'
                        });
                    }

                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        },
        jiaoyan(index){
            this.ajaxGetModelBySoldierId(index)
        },
        updata(){
            debugger
            var Vue = this;
            $.ajax({
                type: 'post',
                url: Url+'FireManApi/InsertFireManInfoModel',
                data: JSON.stringify(Vue.form),
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    if(msg.state == 7){
                        debugger
                        Vue.$message({
                            showClose: true,
                            message: msg.msg,
                            type: 'success'
                        });
                    }
                    if(msg.state == 1){
                        debugger
                       // Vue.form =msg.data
                        Vue.$message({
                            showClose: true,
                            message: msg.msg,
                            type: 'success'
                        });
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        },
        dowm(index){
            var Vue = this;
            $.ajax({
                type: 'post',
                url: Url+'FireManApi/InsertFireManInfoModel',
                data: JSON.stringify({SoldierId:index}),
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    if(msg.state == 1){
                        Vue.$message({
                            showClose: true,
                            message: '成功删除',
                            type: 'success'
                        });
                    }

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        },
        add0(m){
            return m<10?'0'+m:m
        },
        Quit(){
            $.cookie('token', '',{ expires: -1 ,path: '/' });
            window.location.href='../login.html'
        }
    }

})
